﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataTransferObject;
namespace _5ChickDeal.UserControl
{
    public partial class LoginSuccess : System.Web.UI.UserControl
    {
        private String getUsernameFromEmail(String mail)
        {
            String kq = "";

            for (int i = 0; i < mail.Length; i++)
            {
                if (mail[i] != '@')
                {
                    kq += mail[i];
                }
                else
                {
                    break;
                }
            }
            return kq;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                this.Visible = true;
                if (Session["login"] == "google")
                {
                    this.HoTen.InnerText = ((KhachHang)Session["user"]).hoten;
                    avata.ImageUrl = "~/images/avatar_g.png";
                }
                else if (Session["login"] == "yahoo")
                {
                    this.HoTen.InnerText = getUsernameFromEmail(((KhachHang)Session["user"]).email);
                    avata.ImageUrl = "~/images/avatar_yh.png";
                }
                else
                {
                    this.HoTen.InnerText = ((KhachHang)Session["user"]).hoten;
                    avata.ImageUrl = "~/images/avatar_CM.png";
                }


            }
            else
            {
                this.Visible = false;
            }
        }
    }
}